const request = require('request')
var config = require('../appConfig').qqconfig;
/*
*
* https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&
* client_id=[YOUR_APP_ID]&client_secret=[YOUR_APP_Key]&code=[The_AUTHORIZATION_CODE]
* &state=[The_CLIENT_STATE]&redirect_uri=[YOUR_REDIRECT_URI]
*
* */
var getAccessToken_qq = function(code) {
    return new Promise(function (resolve, reject) {
        var url = config.accessTokenUrl+'?grant_type=authorization_code&client_id='+config.appid
            +'&client_secret='+config.secret + '&redirect_uri='+ config.redirect_uri + '&code=' + code
        request.get(url, (err, res, body) => {
            if (err) {
                reject(err)
            }
            if (body.errcode) {
                reject(body.errcode + body.errmsg)
            }
            resolve(body)
        })
    })
}
// 只要向外暴露一个获取值的方法就可以了
module.exports = getAccessToken_qq
